package cn.yh.consumer.msg;

import cn.yh.producer.model.OrderExt;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "demo-consumer-group",topic = "my-topic")
//public class ConsumerSample implements RocketMQListener<String> {
//public class ConsumerSample implements RocketMQListener<OrderExt> {A
public class ConsumerSample implements RocketMQListener<MessageExt> {

    @Override
//    public void onMessage(OrderExt s) {
    public void onMessage(MessageExt messageExt) {
        //取出当前重试次数
        int reconsumeTimes = messageExt.getReconsumeTimes();
        //当大于一定的次数后将消息写入数据库，由单独的程序或人工去处理
        if(reconsumeTimes >=2){
            //将消息写入数据库，之后正常返回
            return ;
        }
        throw new RuntimeException(String.format("第%s次处理失败..",reconsumeTimes));
    }

//        System.out.println(s);
    }
